//
//  UCPath.m
//  AeroMapSDK
//
//  Created by 北京国泰北斗科技有限公司 on 2017/3/10.
//  Copyright © 2017年 北京国泰北斗科技有限公司. All rights reserved.
//

#import "UCPath.h"
#import <GoogleMaps/GoogleMaps.h>

@interface UCPath ()
@property(nonatomic,strong)GMSPath *gmPath;
@end

@implementation UCPath

+ (instancetype)path{

    UCPath *path = [[UCPath alloc] init];
    path.gmPath = [GMSPath path];
    return path;
}

- (id)initWithPath:(UCPath *)path{
    UCPath *myPath = [[UCPath alloc] init];
    path.gmPath = [[GMSPath alloc] initWithPath:path.gmPath];
    return myPath;
}

- (NSUInteger)count{

    return self.gmPath.count;
}

- (CLLocationCoordinate2D)coordinateAtIndex:(NSUInteger)index{

    return [self.gmPath coordinateAtIndex:index];
}


+ (instancetype)pathFromEncodedPath:(NSString *)encodedPath{
    UCPath *myPath = [[UCPath alloc] init];
    myPath.gmPath = [GMSPath pathFromEncodedPath:encodedPath];
    return myPath;
}


- (NSString *)encodedPath{

    return self.gmPath.encodedPath;
}

- (instancetype)pathOffsetByLatitude:(CLLocationDegrees)deltaLatitude
                           longitude:(CLLocationDegrees)deltaLongitude{

    UCPath *myPath = [UCPath path];
    myPath.gmPath = [myPath.gmPath pathOffsetByLatitude:deltaLatitude longitude:deltaLongitude];
    return myPath;
}
@end



@implementation  UCPath (UCPathLength)

- (double)segmentsForLength:(CLLocationDistance)length kind:(UCLengthKind)kind{

    switch (kind) {
        case UCLengthGeodesic:
        {
            return [self.gmPath segmentsForLength:length kind:kGMSLengthGeodesic];
        }
            break;
        case UCLengthRhumb:
        {
            return [self.gmPath segmentsForLength:length kind:kGMSLengthRhumb];
        }
            break;
        case UCLengthProjected:
        {
            return [self.gmPath segmentsForLength:length kind:kGMSLengthProjected];
        }
            break;
    }
    
}


- (CLLocationDistance)lengthOfKind:(UCLengthKind)kind{

    switch (kind) {
        case UCLengthGeodesic:
        {
            return [self.gmPath lengthOfKind:kGMSLengthGeodesic];
        }
            break;
        case UCLengthRhumb:
        {
            return [self.gmPath lengthOfKind:kGMSLengthRhumb];
        }
            break;
        case UCLengthProjected:
        {
            return [self.gmPath lengthOfKind:kGMSLengthProjected];
        }
            break;
    }
}
@end
